//import Vue from 'vue'

import 'leaflet/dist/leaflet.css'
//加载地图
import * as L from 'leaflet'

//import {MAP_SERVER_URL} from '@/config/index.js'
const MAP_SERVER_URL = "http://localhost:9011";

L.TileLayer.LocalProvider = L.TileLayer.extend({

    initialize: function (type, options) { // (type, Object)
        var providers = L.TileLayer.LocalProvider.providers;

        var parts = type.split('.');

        var providerName = parts[0];
        var mapName = parts[1];
        var mapType = parts[2];

        var url = providers[providerName][mapName][mapType];
        options.subdomains = providers[providerName].Subdomains;

        if ('tms' in providers[providerName]) {
            options.tms = providers[providerName]['tms']
        }

        L.TileLayer.prototype.initialize.call(this, url, options);
    }
});

L.TileLayer.LocalProvider.providers = {
    Local: {
        Normal: {
            Map: MAP_SERVER_URL + '/tile/ai/{z}/{x}/{y}'
        },
        Satellite: {
            Map: MAP_SERVER_URL + '/tile/as/{z}/{x}/{y}',
            Annotion: MAP_SERVER_URL + '/tile/ac/{z}/{x}/{y}'
        },
        Subdomains: []
    },
};

L.tileLayer.localProvider = function (type, options) {
    return new L.TileLayer.LocalProvider(type, options);
};

//Vue.prototype.$L = L;
export default L;